import  com.lucastex.grails.fileuploader.UFile

class Article {

    String title
    String content
 
    String category 
    User editor
    Date createTime = new Date()
    Date lastTime  = new Date() //最后编辑时间
  
    Integer hit = 0 //
    static hasMany = [ attachments : UFile, receiver: User , require : Role ]

    Boolean informToMobile = false
    Boolean informToMail = false
    Boolean echo = false
    Boolean broadcast = false // 是否是广播接收，就是所有人都接收

    def beforeSave = {
        if (receiver && !receiver?.isEmpty()) {
            broadcast = false
        }else{
            broadcast = true
        }
    }
    def beforeUpdate = {
        if (receiver && !receiver?.isEmpty()) {
            broadcast = false
        }else{
            broadcast = true
        }
    }
 

    static mapping = {
  
       sort  lastTime : 'desc'
    }

    static constraints = {
        title(size:1..250,blank:false)
        category(size:1..250,blank:false)
        content(size:0..10000,blank:false)
        attachments()

        informToMobile()
        informToMail()
        echo()

        receiver(nullable: true)
        require(nullable: true)

        editor(nullable: true)
        broadcast(nullable: true)
        hit(blank:true)
 

    }

    String toString() {
        "${title}"
    } 
}
